home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-07-15 | 4.5 KB | 177 lines | [TEXT/PJMM] |
- program StyleMap; { Quick and dirty (Think Pascal 3) -- jm (MacDTS), Sept.13, 1991 }
- var
- gWP: WindowPtr;
-
-
- {------------------------------------------------}
- procedure InitMac;
- begin
- InitGraf(@thePort);
- InitFonts;
- FlushEvents(everyEvent, 0);
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(nil);
- InitCursor;
- end;
-
- {------------------------------------------------}
- procedure InitApp;
- var
- bounds: Rect;
- begin
- SetRect(bounds, 0, 0, 480, 290);
- gWP := NewWindow(nil, bounds, 'Click Mouse to Continue', false, documentProc, WindowPtr(-1), false, 0);
- SetPort(gWP);
- MoveWindow(gWP, 10, 50, true);
- ShowWindow(gWP);
- end;
-
- {------------------------------------------------}
- procedure WaitForButton;
- var
- evt: EventRecord;
- done: Boolean;
- begin
- done := false;
- repeat
- SystemTask;
- if GetNextEvent(keyDownMask + mDownMask, evt) then
- done := (evt.what = mouseDown);
- until done;
- end;
-
- {========================================}
- function CompressStyle (aStyle: Style): Integer; { LaserWriter Reference, p. 32 }
- var
- styleCode: Integer;
- begin
- styleCode := 0;
- if bold in aStyle then
- styleCode := styleCode + 1;
- if italic in aStyle then
- styleCode := styleCode + 2;
- if outline in aStyle then
- styleCode := styleCode + 4;
- if shadow in aStyle then
- styleCode := styleCode + 8;
- if condense in aStyle then
- styleCode := styleCode + 16;
- if extend in aStyle then
- styleCode := styleCode + 32;
- CompressStyle := styleCode; { values 0..47 only: condense/extend mutually exclusive }
- end;
-
-
- {------------------------------------------------}
- function BuildPSFontName (id: Integer; aStyle: Style): Str255;
- label
- 99;
- type
- IntegerPtr = ^Integer;
- FamRecPtr = ^FamRec;
- StylMapTable = record { see LaserWriter Reference p. 28 }
- class: Integer;
- offset: Longint;
- reserved: Longint;
- suffixIndex: packed array[0..47] of SignedByte;
- end;
- StylMapPtr = ^StylMapTable;
- var
- h: Handle;
- p: FamRecPtr;
- offSet: Integer;
- smp: StylMapPtr;
- q: Ptr; { pointer to Style-name table: not a good Pascal structure ...}
- nbOfStrings: Integer; { not used }
- PSName, suffixIndices: Str255;
- lg: Integer; { Stringlength }
- i, whichIndex: Integer;
-
- function NthStyleName (index: Integer; q: Ptr): Str255;
- { index 1 => basename, pointed to by q }
- { cf. d e v e l o p Summer 91, p. 100 ! }
- var
- s: Str255;
- begin
- if (index > 1) and (index <= nbOfStrings) then
- begin
- while index > 1 do
- begin
- q := Ptr(ord4(q) + q^ + 1); { assumes q^ = stringlength < 128 ...}
- index := index - 1;
- end;
- BlockMove(q, @s[0], q^ + 1); { assumes q^ = stringlength < 127 ...}
- NthStyleName := s;
- end
- else { FOND corrupted !}
- NthStyleName := '???';
- end;
-
- begin {BuildPSFontName}
- PSName := '';
- TextFace(aStyle);
- h := GetResource('FOND', id);
- if h = nil then
- goto 99; { a reminiscence of AppleSoft }
- HLock(h);
- p := FamRecPtr(h^);
- offSet := p^.ffStylOff;
- if offSet = 0 then { no style-mapping table }
- goto 99; { again ?! }
- smp := StylMapPtr(ord4(p) + offSet);
- q := Ptr(ord4(smp) + SizeOf(StylMapTable)); { style-name table follows style-mappingTable}
- nbOfStrings := IntegerPtr(q)^; { for range checking in "NthStyleName" above }
- q := Ptr(ord4(q) + 2); { now pointing to basename of font }
- BlockMove(q, @PSName, q^ + 1); { basename of font; assumes length < 128 }
- whichIndex := smp^.suffixIndex[CompressStyle(aStyle)];
- if whichIndex > 1 then
- begin
- suffixIndices := NthStyleName(whichIndex, q);
- for i := 1 to ord(suffixIndices[0]) do
- PSName := concat(PSName, NthStyleName(ord(suffixIndices[i]), q));
- end;
- HUnlock(h);
- 99:
- BuildPSFontName := PSName;
- end; {BuildPSFontName}
-
-
- {------------------------------------------------}
- procedure Test;
- var
- fontName: Str255;
- familyID: Integer;
- aStyle: Style;
- begin
- fontName := 'Times';
- GetFNum(fontName, familyID);
- TextFont(familyID);
- TextSize(36);
-
- aStyle := []; { plain }
- MoveTo(30, 60);
- DrawString(BuildPSFontName(familyID, aStyle));
-
- aStyle := [bold];
- MoveTo(30, 120);
- DrawString(BuildPSFontName(familyID, aStyle));
-
- aStyle := [italic];
- MoveTo(30, 180);
- DrawString(BuildPSFontName(familyID, aStyle));
-
- aStyle := [bold, italic];
- MoveTo(30, 240);
- DrawString(BuildPSFontName(familyID, aStyle));
- end;
-
- {------------------------------------------------}
- begin
- InitMac;
- InitApp;
- Test;
- WaitForButton;
- end.
- {------------------------------------------------}